var app = getApp();
var constract = require('../../utils/constract.js');

var type, id, cardId;

Page({
  data: {
    flag:true,
    collect: []
  },
  onLoad:function (options){

    console.log(options);
    
    var that = this;
    var type=options.type;
    id = options.id ? options.id : '';
    cardId = options.cardid ? options.cardid : '';

    this.setData({
      type: type
    });
    
    if (wx.showLoading) {
      wx.showLoading({
        title: '加载中',
        mask: true,
      });
    };
    if (type == 1){
      wx.setNavigationBarTitle({
        title: '点赞我的'
      });
      app.Verification(function (token) {
        wx.request({
          url: constract.findLikeme,
          header: {token:token},
          data:{card_id: cardId},
          success: function (res) {
            console.log(res);
            var collect = res.data.data;
            for (var i = 0; i < collect.length; i++) {
              collect[i].type = 1
            }
            if (wx.hideLoading) {
              wx.hideLoading();
            };
            that.setData({
              collect: res.data.data
            })
          },
          fail: ()=>{
            if (wx.hideLoading) {
              wx.hideLoading();
            };
          }
        })
      })
      
    };
    if (type == 2) {
      wx.setNavigationBarTitle({
        title: '收藏我的'
      });
      app.Verification(function (token) {
        wx.request({
          url: constract.findCollectme,
          header: { token: token },
          data:{card_id: cardId},
          success: function (res) {
            console.log(res);
            var collect = res.data.data;
            for(var i=0;i<collect.length;i++){
              collect[i].type = 1
              collect[i].collectMe = true
            }
            if (wx.hideLoading) {
              wx.hideLoading();
            };
            that.setData({
              collect: collect
            })
          },
          fail: ()=>{
            if (wx.hideLoading) {
              wx.hideLoading();
            };
          }
        })
      })
    };
    if (type == 3){
      wx.setNavigationBarTitle({
        title: 'Ta添加了该印象'
      });
      app.Verification(function(token){
        wx.request({
          url: constract.findImpressMeUser,
          header: { token: token },
          data: { impression_name:options.name},
          success: function(res){
            console.log(res);

            var collect = res.data.data;
            for (var i = 0; i < collect.length; i++) {
              collect[i].type = 1
            }
            if (wx.hideLoading) {
              wx.hideLoading();
            };
            that.setData({
              collect: res.data.data
            })
          },
          fail: ()=>{
            if (wx.hideLoading) {
              wx.hideLoading();
            };
          }
        })
      })
    };
    if (type == 4) {
      wx.setNavigationBarTitle({
        title: '分组联系人'
      });
      app.Verification(function (token) {
        wx.request({
          url: constract.findGroupUser,
          header: { token: token },
          data: { group_id: id }, //*******************
          success: function (res) {
            console.log(res.data.data);
            for(var i=0;i<res.data.data.length; i++){
              res.data.data[i].company_name;
            }

            if (wx.hideLoading) {
              wx.hideLoading();
            };
            that.setData({
              collect: res.data.data,
            })
          },
          fail:()=>{
            if (wx.hideLoading) {
              wx.hideLoading();
            };
          }
        })
      })
    }
  }
  
})